//
//  ASAvatarClassHomeCell.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/29.
//

#import "ASAvatarClassHomeCell.h"

@implementation ASAvatarClassHomeCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.mainImage];
        [self.contentView addSubview:self.bottomView];
        [self.contentView addSubview:self.titleLab];
        
        [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
        }];
        
        [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(25);
        }];
        
        @weakify(self);
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            @strongify(self);
            make.centerX.mas_equalTo(self.bottomView.mas_centerX);
            make.centerY.mas_equalTo(self.bottomView.mas_centerY);
        }];
    }
    return self;
}

- (UIImageView *)mainImage{
    if (!_mainImage) {
        _mainImage = [UIImageView new];
        _mainImage.contentMode = UIViewContentModeScaleAspectFill;
        _mainImage.clipsToBounds = YES;
        _mainImage.layer.masksToBounds = YES;
        _mainImage.layer.cornerRadius = 8;
        [_mainImage setBackgroundColor:[ASTool backgroundRandomColor]];
    }
    return _mainImage;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, (SCREEN_WIDTH - 28 - 7)/2, 25)];
        [_bottomView setBackgroundColor:[UIColor yellowColor]];
        [ASTool addRoundRoundingCorners:(UIRectCornerBottomRight | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(8, 8) subView:_bottomView];
    }
    return _bottomView;
}

- (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = [UIFont systemFontOfSize:13];
        _titleLab.textColor = [UIColor colorWithHexString:@"ffffff"];
        _titleLab.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLab;
}

- (void)setModel:(ASAvatarClassHomeModel *)model{
    _model = model;
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:model.thumb]];
    self.titleLab.text = model.name;
    self.bottomView.backgroundColor = [UIColor colorWithHexString:model.colorStr];
}
@end
